<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
namespace app\components;
use yii\web\Controller;
use app\components\admin_menu;
    use \app\components\API;
    use yii;
class SadminController   extends Controller
{
    const ADMIN_index=1;

    const msg_ok=1;///正确提示框
        const msg_error=2;//错误提示
     ///public $breadcrumbs;//=array();
/*   public function filters(){return array('accessControl', );  }
   public function accessRules()
	{
      /// return array();
       if(API::ADMINISTRATOR()){ return array();}
            return array(
                array('allow',
                 ///   'roles'=>array('Administrator'),
                    'expression'=>'yii::app()->user->isadmin()',
                    ),

             array('deny',///拒绝执行其它情况
                'users'=>array('*'),
            ),

            );
	}*/

     public function init() {
         //   echo    \yii\helpers\Url::to(['/home/public/login']);exit;
              if(API::ADMINISTRATOR()){
                    return parent::init();
              }


              if(yii::$app->user->isGuest){
                  Fun::showmsg('权限怎么就丢了?');
                  yii::$app->user->setReturnUrl(
                  \yii\helpers\Url::to('/admin/view/index')
                          );
                  yii::$app->getResponse()->redirect(
                  \yii\helpers\Url::to(['/home/public/login'])
                          );
                 return ;
              }


              if(!yii::$app->user->identity->isAdmin()){
                  Fun::showmsg('权限怎么就丢了?');
                    yii::$app->user->setReturnUrl(
                  \yii\helpers\Url::to('/admin/view/index')
                          );
                  yii::$app->getResponse()->redirect(
                  \yii\helpers\Url::to(['/home/public/login'])
                          );
              }

              \app\models\Log::addLoginCookie();
              $this->pageTitle=  Lcms::getName();
         return parent::init();
     }




     private $menu;

     /**
      * 获取菜单对象
     */
     public function get_menu(){
         if($this->menu===null){
             $this->menu=new admin_menu;
             return $this->menu;
         }
         return $this->menu;
     }

     public $pageTitle='';

   /*
   public function init() {
    $obj=parent::init();
       //  $this->menu=new admin_menu;
       return $obj;
   }
    *
    */
     public $title='';

      public function ShowMessage($text,$url='',$type=self::msg_ok,$outtime=2000){
                $title='';$this->title;
               echo  $this->render('/Message',array(
                'title'=>$title,
                'text'=>$text,
                'url'=>$url,
                'type'=>$type,
                'outtime'=>$outtime
            ));
               exit;
               ///yii::$app->end();
        }

        public function save_refresh(){
            $this->ShowMessage('保存成功');
        }

}